<?php
declare (strict_types = 1);

namespace app\index\controller;

#[path('/index/controller', 'file path')]
#[class('Play', 'Play data handel')]
class Play extends Base
{
    public function initialize()
    {
        parent::initialize();
    }

    public function index()
    {
        //获取文件后缀
        $suffix = explode(".", $this->path);
        $suffix = strtolower(end($suffix));

        $contents = '';

        switch ($suffix) {
            case 'mp3':
                $html = 'music';
                break;
            case 'mp4':
            case 'm3u8':
            case 'lxe':
                $html = 'video';
                break;
            case 'php':
            case 'html':
            case 'js':
            case 'less':
            case 'scss':
            case 'css':
            case 'py':
            case 'c':
            case 'cpp':
            case 'txt':
            case 'md':
                $contents = $this->file->getContents($this->full_path);
                $html     = 'view';
                break;
            case 'zip':
            case 'gz':
            case 'xz':
            case 'bz2':
                $html = 'zip';
                break;
            case 'png':
            case 'jpeg':
            case 'jpg':
                $html = 'image';
                break;

            default:
                $html = 'view';
                break;
        }

        return view($html, [
            'contents' => $contents,
        ]);
    }

}
